package o;

import android.util.Log;
import androidx.annotation.NonNull;
import com.bumptech.glide.load.engine.GlideException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import o.hg.e;

public class ti<DataType, ResourceType, Transcode> {
    private final Class<DataType> ˊ;
    private final List<? extends se<DataType, ResourceType>> ˋ;
    private final yc<ResourceType, Transcode> ˎ;
    private final String ˏ;
    private final e<List<Throwable>> ॱ;

    interface d<ResourceType> {
        @NonNull
        tx<ResourceType> ॱ(@NonNull tx<ResourceType> txVar);
    }

    public ti(Class<DataType> cls, Class<ResourceType> cls2, Class<Transcode> cls3, List<? extends se<DataType, ResourceType>> list, yc<ResourceType, Transcode> ycVar, e<List<Throwable>> eVar) {
        this.ˊ = cls;
        this.ˋ = list;
        this.ˎ = ycVar;
        this.ॱ = eVar;
        this.ˏ = "Failed DecodePath{" + cls.getSimpleName() + "->" + cls2.getSimpleName() + "->" + cls3.getSimpleName() + "}";
    }

    public tx<Transcode> ˋ(sl<DataType> slVar, int i, int i2, @NonNull sc scVar, d<ResourceType> dVar) throws GlideException {
        return this.ˎ.ˋ(dVar.ॱ(ˊ(slVar, i, i2, scVar)), scVar);
    }

    @NonNull
    private tx<ResourceType> ˊ(sl<DataType> slVar, int i, int i2, @NonNull sc scVar) throws GlideException {
        List list = (List) aas.ˎ(this.ॱ.ˎ());
        try {
            tx<ResourceType> ॱ = ॱ(slVar, i, i2, scVar, list);
            return ॱ;
        } finally {
            this.ॱ.ˋ(list);
        }
    }

    @NonNull
    private tx<ResourceType> ॱ(sl<DataType> slVar, int i, int i2, @NonNull sc scVar, List<Throwable> list) throws GlideException {
        Throwable e;
        tx<ResourceType> txVar = null;
        int size = this.ˋ.size();
        for (int i3 = 0; i3 < size; i3++) {
            se seVar = (se) this.ˋ.get(i3);
            try {
                tx<ResourceType> ˎ;
                if (seVar.ˊ(slVar.ˏ(), scVar)) {
                    ˎ = seVar.ˎ(slVar.ˏ(), i, i2, scVar);
                } else {
                    ˎ = txVar;
                }
                txVar = ˎ;
            } catch (IOException e2) {
                e = e2;
                if (Log.isLoggable("DecodePath", 2)) {
                    Log.v("DecodePath", "Failed to decode data for " + seVar, e);
                }
                list.add(e);
                if (txVar != null) {
                } else if (txVar != null) {
                    return txVar;
                } else {
                    throw new GlideException(this.ˏ, new ArrayList(list));
                }
            } catch (RuntimeException e3) {
                e = e3;
                if (Log.isLoggable("DecodePath", 2)) {
                    Log.v("DecodePath", "Failed to decode data for " + seVar, e);
                }
                list.add(e);
                if (txVar != null) {
                } else if (txVar != null) {
                    return txVar;
                } else {
                    throw new GlideException(this.ˏ, new ArrayList(list));
                }
            } catch (OutOfMemoryError e4) {
                e = e4;
                if (Log.isLoggable("DecodePath", 2)) {
                    Log.v("DecodePath", "Failed to decode data for " + seVar, e);
                }
                list.add(e);
                if (txVar != null) {
                } else if (txVar != null) {
                    return txVar;
                } else {
                    throw new GlideException(this.ˏ, new ArrayList(list));
                }
            }
            if (txVar != null) {
                break;
            }
        }
        if (txVar != null) {
            return txVar;
        }
        throw new GlideException(this.ˏ, new ArrayList(list));
    }

    public String toString() {
        return "DecodePath{ dataClass=" + this.ˊ + ", decoders=" + this.ˋ + ", transcoder=" + this.ˎ + '}';
    }
}
